package com.hexun.es.service.impl;

import com.hexun.es.dao.PersonDao;
import com.hexun.es.model.Person;
import com.hexun.es.service.PersonService;
import com.hexun.es.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @description:人口信息接口实现
 * @author:yrw
 * @date 2018/11/19
 */

@Service
public class PersonServiceImpl implements PersonService {

    @Autowired
    private PersonDao personDao;


    @Override
    public Result add(Person p) {
        try {
            personDao.add(p);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.getFail(e.getMessage());
        }
        return Result.getSuccess();
    }

    @Override
    public Result update(Person p) {
        try {
            personDao.update(p);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.getFail(e.getMessage());
        }
        return Result.getSuccess();
    }

    @Override
    public Result deleteById(Integer id) {
        try {
            personDao.deleteById(id);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.getFail(e.getMessage());
        }
        return Result.getSuccess();
    }

    @Override
    public Result getById(Integer id) {
        Person person = null;
        try {
            person=personDao.getById(id);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.getFail(e.getMessage());
        }
        return Result.getSuccess(person);
    }

    @Override
    public Result findAll() {
        List<Person> personList = null;
        try {
            personList = personDao.findAll();
        } catch (Exception e) {
            e.printStackTrace();
            return Result.getFail(e.getMessage());
        }
        return Result.getSuccess(personList);
    }
}
